package com.bw.liuyushan.mykotlin_firstmvptest.MVVM

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.bw.liuyushan.mykotlin_firstmvptest.MVP.Entity.Data
import com.bw.liuyushan.mykotlin_firstmvptest.MVP.Entity.Food
import io.reactivex.Observer
import io.reactivex.disposables.Disposable

/**
 *MyKotlin_FirstMVPTest
 *file name is : MVVMViewModel
 *created by Ender on 2021/9/16 10:33.
 *author : 刘雨杉
 *Describe:练习的MVVM框架半成品
 */


/**
 * 1,缓存ui的数据
 * 2,处理页面的业务逻辑
 */
class MVVMViewModel : ViewModel() {

    //333333333333----------------------

    val data = MutableLiveData<MutableList<Data>>()


    fun getFood() {
        Repository.getFood(object : Observer<Food> {
            override fun onSubscribe(d: Disposable) {
            }

            override fun onNext(t: Food) {
                Log.i("next", t.data.size.toString())
                data.value = t.data
            }

            override fun onError(e: Throwable) {
            }

            override fun onComplete() {
            }
        })

    }

//222222222222222--------------------------
//
//    private var count = MutableLiveData<Int>()
//
//    var sum:LiveData<Int>
//        get() = count
//
//    init {
//        sum = count
//    }
//
//    fun add(){
//        var v = count.value ?: 0
//        count.value = v + 1
//    }


//1111111111111------------------


//
//    var count = 0
//
//
//    fun add(){
//        //5
//        count++
//    }

}